fix(content): import zod-to-json-schema only for zod v3 schemas - #3826
fix(content): import zod-to-json-schema only for zod v3 schemas#3826lazerg wants to merge 2 commits into
Conversation
|
@lazerg is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe change adds a Zod 3 legacy compatibility module with editor metadata and a chainable Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
🔗 Linked issue
Closes #3825
❓ Type of change
📚 Description
initiateValidatorsContext()imports the zod3 validator dynamically, behind anisPackageInstalled('zod')check, butsrc/utils/index.tsre-exportszfrom that same module. The static re-export wins, sodist/module.mjsends up with a top-levelimport { zodToJsonSchema, ignoreOverride } from 'zod-to-json-schema'and the module cannot load at all unless that package resolves, even for apps whose collections are all zod v4 and go through the nativetoJSONSchema()path.The legacy
zexport and its.editor()prototype patch move toschema/zod3-legacy.ts, which leavesschema/zod3.tsas a converter-only module likezod4.tsandvalibot.ts. It stays out of the eager graph and is loaded only when bothzodandzod-to-json-schemaare present, so a missing converter now surfaces as the existing "installzodandzod-to-json-schema" error instead of a module resolution crash.This only covers the first suggestion in the issue. Widening the zod range and moving zod/zod-to-json-schema to optional peer dependencies changes the dependency contract, so I left it out;
zoditself is still imported eagerly for the legacyzexport.📝 Checklist